package com.lvsc.sdaplacefinder.populate;

import org.apache.log4j.Logger;
import org.hibernate.cfg.Configuration;

import com.lvsc.sdaplacefinder.dao.DataServiceFactory;
import com.lvsc.sdaplacefinder.models.Place;

public class Populate {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(Populate.class);

	public static void main(String[] args) {
		if (logger.isDebugEnabled()) {
			logger.debug("main(String[]) - start");
		}

		// dropBase();
		launch();

		if (logger.isDebugEnabled()) {
			logger.debug("main(String[]) - end");
		}
	}

	public static void launch() {
		if (logger.isDebugEnabled()) {
			logger.debug("launch() - start");
		}

		// ,
		// ibis ,3.198202
		// sofitel 36.750989,3.073425
		// Sheraton 36.762954,2.873611
		Place place = new Place();
		place.setName("Hilton");
		place.setLatitude(36.738557);
		place.setLongitude(3.156692);
		place.setDescription("hotel bla bla");
		place.setCategory(Place.HOTEL);
		place.setImageCount(5);
		DataServiceFactory.getInstance().persist(place);

		place = new Place();
		place.setName("Ibis");
		place.setLatitude(36.714738);
		place.setLongitude(3.198202);
		place.setDescription("hotel bla bla");
		place.setCategory(Place.HOTEL);
		DataServiceFactory.getInstance().persist(place);

		place = new Place();
		place.setName("Sofitel");
		place.setLatitude(36.750989);
		place.setLongitude(3.073425);
		place.setDescription("hotel bla bla");
		place.setCategory(Place.HOTEL);
		DataServiceFactory.getInstance().persist(place);

		place = new Place();
		place.setName("Sheraton");
		place.setLatitude(36.762954);
		place.setLongitude(2.873611);
		place.setDescription("hotel bla bla");
		place.setCategory(Place.HOTEL);
		DataServiceFactory.getInstance().persist(place);

		if (logger.isDebugEnabled()) {
			logger.debug("launch() - end");
		}
	}

	public static void dropBase() {
		if (logger.isDebugEnabled()) {
			logger.debug("dropBase() - start");
		}

		Configuration cfg = new Configuration().configure();
		cfg.setProperty("hibernate.hbm2ddl.auto", "create");
		cfg.buildSessionFactory();

		if (logger.isDebugEnabled()) {
			logger.debug("dropBase() - end");
		}
	}
}
